import React, { Component } from 'react'
import { EventEmitter } from 'events';

const event = new EventEmitter();

class ChileOne extends Component {
    render() {
        return (
            <div>
                <ChileTwo></ChileTwo>
            </div>
        )
    }
}

class ChileTwo extends Component {
    render() {
        return (
            <div onClick={this.send}>ChildTwo</div>
        )
    }
    send() {
        event.emit("listChildEvent","jack",18);
    }
}


export default class Emit extends Component {
    render() {
        return (
            <div>
                <ChileOne></ChileOne>
            </div>
        )
    }

    eventFn(name,age) {
        console.log(name,age);  //jack 18
    }

    componentDidMount() {
        event.addListener("listChildEvent",this.eventFn);
    }

    componentWillUnmount() {
        event.removeListener("listChildEvent",this.eventFn);
    }

}